package Value类型

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object repartition {
    //效果等于coalesce第二个参数为true
    def main(args: Array[String]): Unit = {

        val config: SparkConf = new SparkConf().setMaster("local[*]").setAppName("WordCount")

        val sc = new SparkContext(config)

        val rdd = sc.parallelize(1 to 100, 4)

        println("缩减分区前")
        rdd.glom().collect().foreach(array => {
            println(array.mkString(","))
        })

        // val coalesceRDD: RDD[Int] = rdd.coalesce(3,true)
        val reRDD: RDD[Int] = rdd.repartition(2)

        println("缩减分区后")
        reRDD.glom().collect().foreach(array => {
            println(array.mkString(","))
        })


    }

}
